package com.hepinghospital.user.ui.fragment;//package com.hepinghospital.user.ui.fragment;
//
//import android.graphics.Canvas;
//import android.graphics.Rect;
//import android.os.Bundle;
//import android.os.CountDownTimer;
//
//import androidx.recyclerview.widget.LinearLayoutManager;
//import androidx.recyclerview.widget.RecyclerView;
//
//import android.text.TextUtils;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.hepinghospital.user.base.BaseApplication;
//import com.hepinghospital.user.base.BaseFragment;
//import com.hepinghospital.user.ui.MedicineDetailActivity;
//import util.DpUtil;
//import com.hepinghospital.user.util.ImageLoaderHelper;
//import com.hepinghospital.user.util.ToastUtil;
//import com.rest.business.RestProxy;
//import com.rest.response.BaseResponse;
//import com.rest.response.MedicineOrderResponse;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
//import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
//import com.scwang.smartrefresh.layout.header.ClassicsHeader;
//import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//
//import com.hepinghospital.user.R;
//
//import org.jetbrains.annotations.NotNull;
//
///**
// * Created by HP on 2020/2/25.
// */
//
//public class MedicineListFragment extends BaseFragment {
//
//    @BindView(R.id.refreshLayout)
//    RefreshLayout refreshLayout;
//    @BindView(R.id.recyclerView)
//    RecyclerView recyclerView;
//
//    private String type = "";
//
//    private MyAdapter adapter;
//
//    private List<MedicineOrderResponse.MedicineOrder> list = new ArrayList<>();
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.fragment_cloud_list;
//    }
//
//    @Override
//    protected void initView() {
//        LinearLayoutManager manager = new LinearLayoutManager( mContext );
//        manager.setOrientation( LinearLayoutManager.VERTICAL );
//        recyclerView.setLayoutManager( manager );
//        adapter = new MyAdapter();
//        recyclerView.setAdapter( adapter );
//        recyclerView.addItemDecoration( new RecyclerView.ItemDecoration() {
//            @Override
//            public void onDraw(@NotNull Canvas c, @NotNull RecyclerView parent, @NotNull RecyclerView.State state) {
//                super.onDraw( c, parent, state );
//            }
//
//            @Override
//            public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, @NotNull RecyclerView parent, @NotNull RecyclerView.State state) {
//                super.getItemOffsets( outRect, view, parent, state );
//                outRect.bottom = DpUtil.dip2px( mContext, 10 );
//            }
//        } );
//
//        refreshLayout.setRefreshFooter( new BallPulseFooter( mContext ).setSpinnerStyle( SpinnerStyle.Scale ) );
//        refreshLayout.setRefreshHeader( new ClassicsHeader( mContext ) );
//        refreshLayout.setEnableLoadMore( false );
//        refreshLayout.setOnRefreshListener( refreshlayout -> initData() );
//        refreshLayout.setOnLoadMoreListener( new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//
//            }
//        } );
//    }
//
//    @Override
//    protected void initData() {
////        type = "1";
////        type = getArguments().getString( "type" );
//        getMedicineOrderList();
//    }
//
//
//    public static MedicineListFragment newInstance(String type) {
//        Bundle args = new Bundle();
//        args.putString( "type", type );
//        MedicineListFragment fragment = new MedicineListFragment();
//        fragment.setArguments( args );
//        return fragment;
//    }
//
//    @Override
//    public void onResume() {
//        super.onResume();
//        getMedicineOrderList();
//    }
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        @NotNull
//        @Override
//        public MyAdapter.Holder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
//            MyAdapter.Holder myHolder;
//            myHolder = new MyAdapter.Holder( LayoutInflater.from( getActivity() ).inflate( R.layout.item_my_medicine, parent, false ) );
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(final MyAdapter.Holder holder, final int position) {
//            holder.itemView.setOnClickListener( v -> {
//                Bundle bundle = new Bundle();
//                bundle.putSerializable( "obj", list.get( position ) );
//                startActivity( MedicineDetailActivity.class, bundle );
//            } );
//            holder.tv_department.setText( list.get( position ).deptName );
//            holder.tv_status.setText( getStatus( list.get( position ).orderStatus ) );
//            holder.tv_time.setText( list.get( position ).prescriptionList );
//            holder.tv_price.setText( "¥" + list.get( position ).prescriptionAmount );
//            if (!TextUtils.isEmpty( list.get( position ).expressNum )) {
//                holder.tv_express.setText( list.get( position ).express + ":" + list.get( position ).expressNum );
//            }
//            holder.tv_name.setText( list.get( position ).doctorName );
//            if (list.get( position ).orderStatus == 401) {
//                //将前一个缓存清除
//                if (holder.timer != null) {
//                    holder.timer.cancel();
//                }
//
////                holder.btn_confirm.setVisibility( View.VISIBLE );
//                holder.btn_confirm2.setVisibility( View.VISIBLE );
//                holder.tv_detail.setVisibility( View.VISIBLE );
//
//                final int parseInt = Integer.parseInt( list.get( position ).remainPayTime );
//                holder.timer = new CountDownTimer( parseInt * 1000, 1000 ) {
//                    @Override
//                    public void onTick(long millisUntilFinished) {
//
//                        holder.tv_detail.setText( "请在" + millisUntilFinished / 60000 / 60 + "时" + millisUntilFinished / 60000 % 60 + "分" + (millisUntilFinished / 1000) % 60 + "秒" + "内完成支付" );
////                        holder.tv_detail.setText("请在" + Integer.parseInt(list.get(position).remainPayTime  )/60 + "分"+Integer.parseInt(list.get(position).remainPayTime  )%60 + "秒" + "之内完成支付");
//                    }
//
//                    @Override
//                    public void onFinish() {
//                        //倒计时为0时执行此方法
//                        holder.tv_detail.setText( "已超时" );
//                        holder.timer.cancel();
//                        holder.btn_confirm.setVisibility( View.GONE );
//                        holder.btn_confirm2.setVisibility( View.GONE );
//
//                    }
//                };
//
//                holder.timer.start();
//
//                //holder.tv_detail.setText("请在" + Integer.parseInt(list.get(position).remainPayTime) / 60 + "分钟之内完成支付");
//            } else {
//                holder.btn_confirm.setVisibility( View.GONE );
//                holder.btn_confirm2.setVisibility( View.GONE );
//                holder.tv_detail.setVisibility( View.GONE );
//
//            }
//            holder.btn_confirm.setOnClickListener( v -> cancelOrder( list.get( position ).orderId ) );
//
//
//            ImageLoaderHelper.getInstance().GlideImageLoader( mContext, list.get( position ).url, holder.img_head, R.mipmap.img_default );
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView tv_name, tv_department, tv_status, tv_time, tv_detail, tv_price, tv_express, btn_confirm, btn_confirm2;
//            ImageView img_head;
//            private CountDownTimer timer;
//
//            public Holder(View itemView) {
//                super( itemView );
//                tv_name = itemView.findViewById( R.id.tv_name );
//                tv_status = itemView.findViewById( R.id.tv_status );
//                tv_department = itemView.findViewById( R.id.tv_department );
//                tv_time = itemView.findViewById( R.id.tv_time );
//                tv_detail = itemView.findViewById( R.id.tv_detail );
//                btn_confirm = itemView.findViewById( R.id.btn_confirm );
//                btn_confirm2 = itemView.findViewById( R.id.btn_confirm2 );
//                img_head = itemView.findViewById( R.id.img_head );
//                tv_price = itemView.findViewById( R.id.tv_price );
//                tv_express = itemView.findViewById( R.id.tv_express );
//            }
//        }
//    }
//
//    private void getMedicineOrderList() {
//        RestProxy.getInstance().getMedicineOrderList( BaseApplication.currentUserId, "1", new Observer<MedicineOrderResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(MedicineOrderResponse medicineOrderResponse) {
//                list.clear();
//                list.addAll( medicineOrderResponse.data );
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                ToastUtil.onError( mContext, e );
//                refreshLayout.finishRefresh( false );
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishRefresh( true );
//            }
//        } );
//    }
//
//    private void cancelOrder(String orderId) {
//        RestProxy.getInstance().cancelOrder( orderId, new Observer<BaseResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(BaseResponse baseResponse) {
//                getMedicineOrderList();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                ToastUtil.onError( mContext, e );
//            }
//
//            @Override
//            public void onComplete() {
//
//            }
//        } );
//    }
//
//
//    private String getStatus(int status) {
//        switch (status) {
//            case 401:
//                return "待支付";
//            case 402:
//                return "未发货";
//            case 403:
//                return "已发货";
//            case 404:
//                return "已收货";
//            case 405:
//                return "待领取";
//            default:
//                return "";
//        }
//    }
//
//}
